<html>
<head><meta charset="utf-8"><title>test error location output · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/test.20error.20location.20output.html">test error location output</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240858932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/test%20error%20location%20output/near/240858932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/test.20error.20location.20output.html#240858932">(May 31 2021 at 18:03)</a>:</h4>
<p>Has there been any discussion on having error/panic output from <code>#[tests]</code> always include the last invoked line from the function which actually has the <code>#[test]</code> attribute? Would this even be possible? This information is in backtraces but it's often buried, and is not approachable for new rust users. This means all test helpers that could cause assertions need to be macros to get immediately usable source line info, which is not always practical. (Sorry don't know where else to ask!)</p>



<a name="240859037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/test%20error%20location%20output/near/240859037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/test.20error.20location.20output.html#240859037">(May 31 2021 at 18:04)</a>:</h4>
<p>if backtraces bury this information then perhaps that should be fixed</p>



<a name="240859098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/test%20error%20location%20output/near/240859098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/test.20error.20location.20output.html#240859098">(May 31 2021 at 18:05)</a>:</h4>
<p>When you mention error/panic information, do you mean things like <code>Err</code>s from <code>?</code> too?</p>



<a name="240859558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/test%20error%20location%20output/near/240859558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/test.20error.20location.20output.html#240859558">(May 31 2021 at 18:12)</a>:</h4>
<blockquote>
<p>do you mean things like Errs from ? too?</p>
</blockquote>
<p>this seems like the kind of thing that would be great honestly, although it also seems quite hard. this is why i tell people to prefer <code>unwrap()</code> to <code>?</code> in test code</p>



<a name="240860380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/test%20error%20location%20output/near/240860380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/test.20error.20location.20output.html#240860380">(May 31 2021 at 18:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span> <a href="#narrow/stream/122651-general/topic/test.20error.20location.20output/near/240859558">said</a>:</p>
<blockquote>
<p>although it also seems quite hard</p>
</blockquote>
<p>There're a few possibilities.  Check out this little experiment: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2021&amp;gist=8ca138947ac046ea4d0bfb0e4cb8c261">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2021&amp;gist=8ca138947ac046ea4d0bfb0e4cb8c261</a></p>



<a name="240861541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/test%20error%20location%20output/near/240861541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/test.20error.20location.20output.html#240861541">(May 31 2021 at 18:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span> <a href="#narrow/stream/122651-general/topic/test.20error.20location.20output/near/240859558">said</a>:</p>
<blockquote>
<blockquote>
<p>do you mean things like Errs from ? too?</p>
</blockquote>
<p>this seems like the kind of thing that would be great honestly, although it also seems quite hard. this is why i tell people to prefer <code>unwrap()</code> to <code>?</code> in test code</p>
</blockquote>
<p>At my employer we moved to <code>unwrap()</code> but now we're moving back to <code>?</code> because the difference isn't actually that much according to my tests this morning. The big problem for us seems to be indirection from helper functions that could cause errors / assertions.</p>



<a name="240861582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/test%20error%20location%20output/near/240861582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/test.20error.20location.20output.html#240861582">(May 31 2021 at 18:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/122651-general/topic/test.20error.20location.20output/near/240859098">said</a>:</p>
<blockquote>
<p>When you mention error/panic information, do you mean things like <code>Err</code>s from <code>?</code> too?</p>
</blockquote>
<p>By panics I mean <code>panic!</code> / <code>assert!</code>, and by errors I mean <code>Result&lt;&gt;</code>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>